﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using System.Data.Common;

namespace GenerateDiagram
{
    public class SqlDataConnection : DataConnection
    {
        public override System.Data.Common.DbConnection CreateConnection()
        {
            return new SqlConnection(this.ConnectionString);
        }

        public override DataTable ExecuteReader(string commandText, string databaseName)
        {
            DataConnection.Instance.ConnectionString = Config.GetConnectionString(databaseName);
            DbConnection dbconnection = DataConnection.Instance.CreateConnection();
            SqlCommand cm = (SqlCommand)dbconnection.CreateCommand();
            cm.CommandText = commandText;
            SqlDataAdapter adap = new SqlDataAdapter();
            adap.SelectCommand = cm;
            DataSet ds = new DataSet();
            adap.Fill(ds);
            return ds.Tables[0];
        }
    }
}
